package com.gun.management.module.task.dal.mysql.taskInfo;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gun.management.framework.common.pojo.PageResult;
import com.gun.management.framework.mybatis.core.mapper.BaseMapperX;
import com.gun.management.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.gun.management.module.task.controller.admin.taskInfo.vo.TaskInfoPageReqVO;
import com.gun.management.module.task.controller.app.vo.AppTaskInfoRespVO;
import com.gun.management.module.task.dal.dataobject.taskInfo.TaskInfoDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 任务信息 Mapper
 *
 * @author 测试账号
 */
@Mapper
public interface TaskInfoMapper extends BaseMapperX<TaskInfoDO> {

    default PageResult<TaskInfoDO> selectPage(TaskInfoPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<TaskInfoDO>()
                .eqIfPresent(TaskInfoDO::getAvatar, reqVO.getAvatar())
                .likeIfPresent(TaskInfoDO::getName, reqVO.getName())
                .eqIfPresent(TaskInfoDO::getTaskIntroduct, reqVO.getTaskIntroduct())
                .eqIfPresent(TaskInfoDO::getCategoryId, reqVO.getCategoryId())
                .eqIfPresent(TaskInfoDO::getRewardScore, reqVO.getRewardScore())
                .eqIfPresent(TaskInfoDO::getDayRewardTimes, reqVO.getDayRewardTimes())
                .eqIfPresent(TaskInfoDO::getMaxRewardTimes, reqVO.getMaxRewardTimes())
                .likeIfPresent(TaskInfoDO::getButtonName, reqVO.getButtonName())
                .eqIfPresent(TaskInfoDO::getStatus, reqVO.getStatus())
                .eqIfPresent(TaskInfoDO::getContent, reqVO.getContent())
                .eq(TaskInfoDO::getDeleted,0)
                .eqIfPresent(TaskInfoDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(TaskInfoDO::getCreateTime, reqVO.getCreateTime())
                .orderByAsc(TaskInfoDO::getSeqNo, TaskInfoDO::getId));
    }


    @Select({"<script> " +
            " SELECT" +
            " A.id , " +
            " A.avatar, " +
            " A.`name` name , " +
            " A.task_introduct, " +
            " A.category_id, " +
            " A.reward_score, " +
            " A.day_reward_times, " +
            " A.max_reward_times, " +
            " A.button_name, " +
            //  " A.jump_url, " +
            " A.`status`, " +
            " A.content " +
            " FROM " +
            "task_info  A " +
            "<where>" +
            "   A.deleted = 0 and A.status = 0 " +
            "<if test='taskId != null  '>" +
            " and A.id =  #{taskId}  " +
            "</if>" +
            "<if test='categoryId != null  '>" +
            " and A.category_id =  #{categoryId}  " +
            "</if>" +
            "<if test='taskName != null and taskName != \"\"'>" +
            " and A.name like concat('%',#{taskName},'%')" +
            "</if>" +
//                "<if test='status != null '>" +
//                " and A.status =  #{status}  " +
//                "</if>   " +
            "<if test='content != null and content != \"\"'>" +
            " and A.content like concat('%',#{content},'%')" +
            "</if>" +
            "</where>" +
            " order by A.seq_no,A.id Asc " +
            "</script>"})
    public IPage<AppTaskInfoRespVO> getTaskPageList(IPage<?> page, @Param("taskId") Long taskId, @Param("categoryId") Long categoryId, @Param("taskName") String taskName, @Param("status") Integer status, @Param("content") String content);

}